package com.tl.web03.service;

import com.tl.web03.config.Config;
import com.tl.web03.constant.ResponseResult;
import com.tl.web03.model.entity.User;

import javax.servlet.ServletContext;
import java.util.HashMap;

public class UserService {
    //根据用户名查找用户
    public static ResponseResult findUserByUserName(HashMap<String, User> map, String username) {
        User user = map.get(username);
        return new ResponseResult<User>("查询成功", 200,  user);
    }
    //删除用户
    public static ResponseResult delUser(HashMap<String, User> map, String username) {
        map.remove(username);
        return new ResponseResult<Boolean>("删除成功", 200, true);
    }
    //编辑用户
    public static ResponseResult modify(ServletContext application, User user){
        HashMap<String,User> map = (HashMap<String, User>) application.getAttribute(Config.USER_MAP);
        map.put(user.getUsername(),user);
        return new ResponseResult("编辑成功",200,true);
    }
}
